package cn.imvc.app.controllers.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.entities.Role;
import cn.imvc.app.models.RoleModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;

public class RoleControllerImpl implements RoleController {
	
	public Page<Role> page;
	public ViewRequest viewRequest;
	public Role role;
	public int id;
	public int[] ids;
	@Autowired
	RoleModel roleModel;
	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}


	public void setRole(Role role) {
		this.role = role;
	}


	public void setId(int id) {
		this.id = id;
	}

	public void setIds(int[] ids) {
		this.ids = ids;
	}

	public String search() {
		// TODO Auto-generated method stub
		return "role/search";
	}

	public String index() {
		page=roleModel.find(viewRequest);
		return "role/index";
	}

	public String show() {
		role=roleModel.get(id);
		return "role/show";
	}
	
	public String detail() {
		role=roleModel.get(id);
		return "role/detail";
	}

	public String editNew() {
		// TODO Auto-generated method stub
		return "role/editNew";
	}

	public String create() {
		roleModel.save(role);
		return Render.json(new DialogBean("200", "创建成功","role", "closeCurrent"));
	}

	public String edit() {
		role=roleModel.get(id);
		return "role/edit";
	}

	public String update() {
		roleModel.update(id, role);
		return Render.json(new DialogBean("200", "修改成功","role", "closeCurrent"));
	}

	public String destroy() {
		roleModel.delete(id);
		return Render.json(new DialogBean("200", "删除成功","role"));
	}

	public String destroyBatch() {
		roleModel.deleteBatch(ids);
		return Render.json(new DialogBean("200", "删除成功","role"));
	}

}
